/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.manage.entrepot;
import shop.core.common.bean.JSONResult;
import shop.core.common.dao.page.PagerModel;
import shop.core.util.KeyValueHelper;
import shop.core.Services;
import shop.core.util.MD5;
import shop.services.manage.entrepot.EntrepotService;
import shop.services.manage.entrepot.bean.Entrepot;
import shop.core.BaseController;
import shop.core.RequestHolder;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**   
 * @类名称：EntrepotAction      
 * @创建人：Ltz   
 * @创建时间：2017-10-24 上午09:59:14      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/manage/entrepot/")
public class EntrepotAction extends BaseController<Entrepot> {
    private static final Logger logger = LoggerFactory.getLogger(EntrepotAction.class);

    private static final String page_toList = "/manage/entrepot/entrepotList";
    private static final String page_toSendDetail = "/manage/entrepot/SendDetail";
    private static final String page_toStayDetail = "/manage/entrepot/stayDetail";

    @Autowired
    private EntrepotService entrepotService;

    public EntrepotService getService() {
        return entrepotService;
    }

    private EntrepotAction(){
        super.page_toList = page_toList;
        super.page_toAdd = null;
        super.page_toEdit = null;
    }

    /**
     * 跳转到已提货详情页面
     * @param model
     * @param e
     * @return
     * @throws Exception
     */
    @RequestMapping("toSendDetail")
    public String toSendDetail(ModelMap model, @ModelAttribute("e") Entrepot e) throws Exception {
        model.addAttribute("e",e);
        return page_toSendDetail;
    }

    /**
     * 跳转到未提货详情页面
     * @param model
     * @param e
     * @return
     * @throws Exception
     */
    @RequestMapping("toStayDetail")
    public String toStayDetail(ModelMap model, @ModelAttribute("e") Entrepot e) throws Exception {
        model.addAttribute("e",e);
        return page_toStayDetail;
    }

    /**
     * 分页查询未提货商品列表
     * @param request
     * @param e
     * @return
     */
    @RequestMapping("loadStayData")
    @ResponseBody
    public PagerModel loadStayData(HttpServletRequest request, Entrepot e) {
        int offset = 0;
        int pageSize = 10;
        if (request.getParameter("start") != null) {
            offset = Integer.parseInt(request.getParameter("start"));
        }
        if (request.getParameter("length") != null) {
            pageSize = Integer.parseInt(request.getParameter("length"));
        }
        if (offset < 0)
            offset = 0;
        if (pageSize < 0) {
            pageSize = 10;
        }
        e.setOffset(offset);
        e.setPageSize(pageSize);
        PagerModel pager = entrepotService.selectPageStayList(e);
        pager.setRecordsTotal(pager.getTotal());
        pager.setRecordsFiltered(pager.getTotal());
        return pager;
    }
}
